<?php

/*
    Function: phptal_tales_validation_value
    PHPTAL Tales to get a validation value in Codeigniter
    
    Usage:
        Simply use it as any other tale
        > <input type="text" name="input_name" tal:attributes="value validation-value:input_name | default" />
        Here the tale is *validation-value:input_name | default* the `value`
        attribute will become whatever the value of the validation field
        `input_name` is. If it has not been set yet, * | default* will be used
        but this is optional
*/
function phptal_tales_validation_value($src, $nothrow)
{
    $_ci =& get_instance();
    
    $args = explode('|', $src);
    $args = array_map('trim', $args);
    $validation_field = $args[0];
    $alt_string = isset($args[1]) ? $args[1] : 'nothing';
    
    if(isset($_ci->validation->$validation_field)) {
        $r = '$GLOBALS[\'_ci\']->validation->{'.PHPTAL_TalesInternal::string($validation_field).'}';
    }else{
        if($alt_string=='default' || $alt_string=='nothing') {
            $r = array('false', PHPTAL_TalesInternal::path($alt_string, $nothrow));
        }else{
            $r = PHPTAL_TalesInternal::path($alt_string, $nothrow);
        }
    }
    
    return $r;
}

?>